<?php
  class Zend_View_Helper_Box extends Zend_View_Helper_Abstract{
    protected $_viewRenderer;

    public function __construct(){
      $this->_viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
    }

    public function box($_params){
      if(is_string($_params)){
        $params['message'] = $_params;
      }
      else{
        $params = $_params;
      }

      // set the icon based on iconCode
      if( isset($params['icon'] )){
        $params['icon'] = $this->_getIcon($params['icon']);
      }

      // set all the params on template
      foreach( $params as $key => $value ){
        $this->view->assign($key, $value);
      }

      $this->_viewRenderer->setRender(isset($params['template']) ? $params['template'] : 'helper-box/message', null, true);
    }

    /**
     * Retorna o nome do icone de acordo com o codigo informado
     *
     * @param int $iconCode
     * @return string
     */
    protected function _getIcon($iconCode){
      switch ( (int) $iconCode){
        case 1:
          $strIcon = 'info';
        break;
        
        case 2:
          $strIcon = 'warning';
        break;
        
        case 3:
          $strIcon = 'error';
        break;
        
        case 4:
          $strIcon = 'ask';
        break;
        
        case 5:
          $strIcon = 'success';
        break;
      }
      return (isset($strIcon) ? $strIcon : $iconCode) . '.png';
    }

  }